package com.elite;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class test1 {
	private static final Log log=LogFactory.getLog(test1.class);
	public static void getFilePath(String path){
		File file = new File(path);
		if(file==null){
			log.info("没有文件");
		}else{
			log.info("新文件的个数："+file.listFiles().length);
		}
		if(file.listFiles().length>0){
			for (int i = 0; i < file.listFiles().length; i++){
				log.info("文件路径：" + file.listFiles()[i].getPath());
				log.info("文件名：" + file.listFiles()[i].getName());
			}
		}else{
			log.info("没有新文件");
		}

	}
	
	public static void CreateFile(String path){
		try{
			File dirFile  =   new  File(path);
             if ( ! (dirFile.exists())  &&   ! (dirFile.isDirectory())) {
                 boolean  creadok  =  dirFile.mkdirs();
                 if (creadok) {
                	 log.info( " ok:创建文件夹成功！ " );
                } else {
                	log.info( " err:创建文件夹失败！ " );                    
                } 
		}	
	}catch(Exception e){
		log.info("创建文件夹失败:"+e);
	}
	}
	
	public static void changeDirectory(String filename,String oldpath,String newpath,boolean cover){   
	    if(!oldpath.equals(newpath)){   
	        File oldfile=new File(oldpath+"/"+filename);   
	        File newfile=new File(newpath+"/"+filename);   
	        if(newfile.exists()){//若在待转移目录下，已经存在待转移文件   
	            if(cover){
	            	oldfile.renameTo(newfile); //覆盖   
	            }else{
	            	log.info("在新目录下已经存在："+filename); 
	            }
	        }   
	        else{   
	            oldfile.renameTo(newfile);   
	        }   
	    }          
	}
	public static void main(String arg[]) throws IOException{
//		getFilePath("C:\\aaaaa");
//		CreateFile("C:\\aaaaaB");
//		changeDirectory("cccccccc.txt","C:/aaaaa","C:/aaaaaB",true);
//		String filename1="BADAF948-C155-F471-B790-7C3A4671990B.txt";
//		String name1="";
//		int a1=filename1.lastIndexOf(".");
//		System.out.println(filename1.substring(0, filename1.lastIndexOf(".")));

//		  for(int i=0;i<a1.length;i++)
//		  {
//		   System.out.println(a1[i]);
//		  }
		String a="测试";
		
		String url1="http://220.194.54.161:9010/index.aspx?action=sendsms&username=glodon01&password=201102111532&mobile=13636445902&content=TEST&dstime=&xh=123456";
		System.out.println(URLEncoder.encode("Glodon测试短信 to wang zheng","GBK"));
		URL url=new URL(url1); 
        URLConnection conn=url.openConnection(); 
        conn.setDoOutput(true); 
        OutputStreamWriter wr=new OutputStreamWriter(conn.getOutputStream()); 
        BufferedReader rd=new BufferedReader(new InputStreamReader(conn.getInputStream())); 
        String line =rd.readLine(); 
        System.out.println("line:"+line);
	
//	String a="新契约回访数据.xls";
//	System.out.println(a.length());
//	System.out.println(a.substring(0, a.lastIndexOf(".")));
	
	
	}
	
	
	
}
